﻿using System;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;


namespace AnyOffice.general.attend.personal
{
    public partial class _out : ModulePage
    {

        public string GetStatusName(int allow)
        {
            switch (allow)
            {
                case 0:
                    return "待批";

                case 1:
                    return "批准";

                case 2:
                    return "未批准";
            }
            return "";
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                this.txtCreateDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
                this.txtOutTime1.Value = DateTime.Now.ToString("HH:mm");
                this.txtOutTime2.Value = DateTime.Now.ToString("HH:mm");
                AttendParaDao dao = new AttendParaDao();
                dao.GetPara();
                DataTable table = dao.SelectAttendManager(base.Conn);
                if (table.Rows.Count > 0)
                {
                    this.sltLeaderId.DataSource = table;
                    this.sltLeaderId.DataBind();
                }
                this.ckbMobile.Visible = SmsDao.IsMobile(SmsDao.SmsType.Attend);
                DataTable table2 = new AttendOutDao().SelectMy(base.Conn, base.User.Identity.Name);
                if (table2.Rows.Count > 0)
                {
                    this.rptOut.DataSource = table2;
                    this.rptOut.DataBind();
                }
            }
            if (this.Page.IsPostBack)
            {
                AttendOutDao dao2 = new AttendOutDao();
                AttendOutData data = new AttendOutData();
                data.UserId = base.User.Identity.Name;
                data.LeaderId = this.sltLeaderId.Value;
                if (this.txtOutType.Value != string.Empty)
                {
                    data.OutType = this.txtOutType.Value;
                }
                data.CreateDate = Convert.ToDateTime(this.txtCreateDate.Value);
                data.SubmitTime = DateTime.Now;
                data.OutTime1 = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + this.txtOutTime1.Value + ":00");
                data.OutTime2 = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " " + this.txtOutTime2.Value + ":00");
                dao2.Insert(base.Conn, data);
                if (this.sltLeaderId.Value != string.Empty)
                {
                    SmsData data2 = new SmsData();
                    SmsDao dao3 = new SmsDao();
                    data2.Type = 6;
                    data2.FromId = base.User.Identity.Name;
                    data2.ToId = this.sltLeaderId.Value;
                    data2.Content = new UserCache().UserName + "提交外出申请，请批示！";
                    data2.RemindFlag = true;
                    data2.Url = "/general/attend/manage";
                    data2.SendTime = DateTime.Now;
                    dao3.BizSend(base.Conn, data2, true, this.ckbMobile.Checked);
                }
                this.pnlMain.Visible = false;
                this.litMessage.Text = base.ShowPrompt("外出申请添加成功！", "out.aspx");
            }
        }
 

    }
}
